package com.byq.mm.gateway;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.byq.mm.gateway.HorizontalSlider.OnProgressChangeListener;
import com.tc.gateway.GatewayEngine;
import com.tc.gateway.device.ha.*;


public class DimmableLightActivity extends Activity{
	
	private HorizontalSlider slider;
	private GatewayEngine manager;
	private DimmableLight device;
	
	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		AssistanceApplication app = (AssistanceApplication)this.getApplication();
		AndroidHomeApplication ha = (AndroidHomeApplication)app.getHomeApplication();
		manager = ha.getGatewayEngine();
		short node = this.getIntent().getExtras().getShort("node");
		String endpoint = this.getIntent().getExtras().getString("id");
		device = (DimmableLight)manager.getDeviceManager().getDevice(endpoint);
		setContentView(R.layout.dimmablelight);


		slider = (HorizontalSlider) this.findViewById(R.id.slider);
		slider.setOnProgressChangeListener(changeListener);
		Button incre = (Button) this.findViewById(R.id.increment);
		
		incre.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				int p = slider.getProgress();
				 p += 20;
				 if(p > 255)
					 p = 255;
					 
				 slider.setProgress(p);
					device.level(p);
			}
		});
		Button decre = (Button) this.findViewById(R.id.decrement);
		decre.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				int p = slider.getProgress();
				 p -= 20;
				 if(p < 0)
					 p = 0;
					 
				 slider.setProgress(p);
					device.level(p);
				
			}
		});
		Button onoff = (Button) this.findViewById(R.id.onoff);
		onoff.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				device.toggle();
			}
		});
	}

	private OnProgressChangeListener changeListener = new OnProgressChangeListener() {

		public void onProgressChanged(View v, int progress) {
		
//			setProgress(progress);
	//		device.action(progress);
		
		}

	};
	
}
